package com.msf.tutorial.java8.chapter10;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * reducing归约
 */
public class C02Reducing {

    public static void sum() {
        List<Integer> list = Arrays.asList(1, 2, 3, 4, 5);
        int sum = list.stream().collect(Collectors.reducing(0, i -> i, Integer::sum));
        System.out.println(sum);
    }

    public static void count() {
        List<Integer> list = Arrays.asList(1, 2, 3, 4, 5);
        int count = list.stream().collect(Collectors.reducing(0, i -> 1, Integer::sum));
        System.out.println(count);
    }

    public static void max() {
        List<Integer> list = Arrays.asList(1, 2, 3, 4, 5);
        int max = list.stream().collect(Collectors.reducing(Integer::max)).get();
        System.out.println(max);
    }

    public static void min() {
        List<Integer> list = Arrays.asList(1, 2, 3, 4, 5);
        int min = list.stream().collect(Collectors.reducing(Integer::min)).get();
        System.out.println(min);
    }

    public static void main(String[] args) {
        max();
        min();
    }

}
